# 黎视频-好看视频 https://haokan.baidu.com/author/1604516469959595?pd=wisenatural
import requests
from lxml import etree

url = 'https://haokan.baidu.com/author/1604516469959595'

params = {
    'pd': 'wisenatural'
}

# UA伪装: 将对应的User-Agent封装到一个字典中
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
    # 'Cookie': 'BIDUPSID=C73FFA6E3B56E9AB2BDFBED02422F75F; PSTM=1713674862; newlogin=1; BAIDUID=90ECB24100994F71BDF6685D3BC1F5F8:FG=1; H_PS_PSSID=40463_60269_60285_60287_60297; H_WISE_SIDS=40463_60269_60285_60287_60297; H_WISE_SIDS_BFESS=40463_60269_60285_60287_60297; BAIDUID_BFESS=90ECB24100994F71BDF6685D3BC1F5F8:FG=1; ZFY=VGxEI7iWCpjmB:B0NHtYeSQamGWWbOP3Gj:BG9gcFKF1Y:C; b2b_first=1716145237; BDRCVFR[PaHiFN6tims]=9xWipS8B-FspA7EnHc1QhPEUf; delPer=0; PSINO=3; BA_HECTOR=8h8584250h2hal2g8k24812hdmho4o1j4n9m01v; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; Hm_lvt_4aadd610dfd2f5972f1efee2653a2bc5=1716233948; PC_TAB_LOG=video_details_page; COMMON_LID=def82635e4aa4648bb733b1b2b094da2; Hm_lpvt_4aadd610dfd2f5972f1efee2653a2bc5=1716234414; ab_sr=1.0.1_MjMxZGIwYTU4MzEwNDkzODA5OTY5MTQ5OWUxNTc1MDBhYWE5ZDM3Y2YyMDg3NmE0MzAzNDA4ZTUwYzM0NTY1N2U4MjdjMGMxOGYzZTgwNjAwNjE0YjA5OTQ4M2M2NzVlMTIzY2MzNWZhYTJiZjZlOGE3OGFhYzk1MDE0NTViMTVjMDE1NGJmYWNmMDNhZTE2MjkyYWJjOTRkMmYxZjJjMDRiMmMwODQxOTM2M2IzYTRmMGFjNTZhZTE0MzdlNmVjYjQ1YTQxNDI1NmRlN2NiN2JjZTQxZDAxYWU5YmU1ZmM=; reptileData=%7B%22data%22%3A%22e982b8160d1695742a7e285d33b6adb1466d1837adb2571cd0c6b6376651efc514de824e2e038b7b62f30c169cfb143878f82df6821333ad9c5875685bffa2f45d27e214dab0c2afdcfd16922bb324b8a29b7226f6d41f2c02a283646eb95a57032a6ea0a7f16ab20ad7b14e2c5e587ed3ccb10373e565adc26775eca543d6f0%22%2C%22key_id%22%3A%2230%22%2C%22sign%22%3A%22e39d6312%22%7D; RT="z=1&dm=baidu.com&si=099fc4d3-cdfc-4767-b9f1-9a1317da683e&ss=lwfddoq3&sl=3&tt=2t9&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=9s4b&nu=5nmnxhx&cl=hje&ul=go7x"'
}

session = requests.session()

response = session.get(url=url,headers=headers,params=params)

# print(response.text)

tree = etree.HTML(response.text)

lst_a = tree.xpath('//div[@class="skeleton-video"]/a')

for a in lst_a:
    video_url = 'https://haokan.baidu.com'+a.xpath('./@href')[0]
    video_name = a.xpath('./div[2]/text()')[0]

    resp = session.get(url=video_url,headers=headers)

    print(video_name+'  '+video_url)

    # tree = etree.HTML(resp.text)

    with open('1.html','w',encoding='utf-8') as f:
        f.write(resp.text)
    break


